<%--
  Created by IntelliJ IDEA.
  User: sundezeng
  Date: 2018/9/28
  Time: 18:14
  To change this template use File | Settings | File Templates.
  区域单价表
--%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>

<html>
<head>
    <base href="<%=basePath%>">
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>区域单价表</title>
    <!--框架必需start-->
    <script src="/Content/scripts/jquery/jquery-1.10.2.min.js"></script>
    <link href="/Content/styles/font-awesome.min.css" rel="stylesheet" />
    <link href="/Content/scripts/plugins/jquery-ui/jquery-ui.min.css" rel="stylesheet" />
    <script src="/Content/scripts/plugins/jquery-ui/jquery-ui.min.js"></script>

    <link href="/Content/scripts/bootstrap/bootstrap.min.css" rel="stylesheet" />
    <link href="/Content/scripts/bootstrap/bootstrap.extension.css" rel="stylesheet" />
    <script src="/Content/scripts/bootstrap/bootstrap.min.js"></script>
    <script src="/Content/scripts/plugins/datepicker/WdatePicker.js"></script>
    <link href="/Content/scripts/plugins/tree/tree.css" rel="stylesheet"/>
    <link href="/Content/scripts/plugins/datetime/pikaday.css" rel="stylesheet"/>
    <link href="/Content/scripts/plugins/wizard/wizard.css" rel="stylesheet"/>
    <script src="/Content/scripts/plugins/validator/validator.js"></script>
    <script src="/Content/scripts/plugins/datepicker/DatePicker.js"></script>
    <script src="/Content/scripts/plugins/jquery.md5.js"></script>
    <script src="/Content/scripts/utils/jet-pinyin.js"></script>
    <script src="/Content/scripts/plugins/layout/jquery.layout.js"></script>
    <script src="/Content/scripts/plugins/datepicker/WdatePicker.js"></script>
    <link href="/Content/scripts/plugins/jqgrid/jqgrid.css" rel="stylesheet"/>
    <link href="/Content/scripts/plugins/datetime/pikaday.css" rel="stylesheet"/>
    <link href="/Content/styles/jet-ui.css" rel="stylesheet"/>
    <script src="/Content/scripts/plugins/jqgrid/grid.locale-cn.js"></script>
    <script src="/Content/scripts/plugins/jqgrid/jqgrid.js"></script>
    <script src="/Content/scripts/plugins/tree/tree.js"></script>
    <script src="/Content/scripts/plugins/validator/validator.js"></script>
    <script src="/Content/scripts/plugins/datepicker/DatePicker.js"></script>
    <script src="/Content/scripts/utils/jet-ui.js"></script>
    <script src="/Content/scripts/utils/jet-form.js"></script>
</head>
<body>
<form id="form1">

    <script>
        var keyValue = request('pid');
        $(function () {
            $("#zlinterval").ComboBox({
                description: "==请选择==",
                height: "200px",
                data: top.clientdataItem.zlinterval
            })
//            initControl();
            GetGrid();
        })
        //初始化控件
//        function initControl() {
//            //加载自定义表单
//            //获取表单
//            if (!!keyValue) {
//                $.SetForm({
//                    url: "/deleveryPrice/selectBean.action",
//                    param: {tableName:"JC_DELIVERY_PRICE",id: keyValue },
//                    success: function (data) {
//                        $("#form1").SetWebControls(data);
//                    }
//                });
//            }
//
//        }
        //保存表单
        function AcceptClick() {
            if (!$('#form1').Validform()) {
                return false;
            }
            var postData ={
                id: $("#id").val(),
                name:$("#name").val(),
                zlinterval:$("#zlinterval").attr('data-value'),
                pirce:$("#pirce").val(),
                "serverZone.id":keyValue,
            }
            $.SaveForm({
                url: "/deleveryPrice/saveDeleveryPrice.action?key="+ keyValue,
                param:postData,
                loading: "正在保存数据...",
                success: function (data) {
                    if (data.type == "validator") {
                        $('#form1').ValidformResule(data.obj);//后台验证数据
                    }else if (data.type){
                      $("#gridTable").trigger("reloadGrid");
                        dialogMsg(data.obj, 1);
                        $("#zlinterval").ComboBoxSetNotValue()
                       $("#pirce").val(null);
                    }else{
                        dialogAlert(data.obj, -1);
                    }
                }
            })
        }
        function btn_edit(){
            var id = $("#gridTable").jqGridRowValue("id");
//            var zlinterval=$("#gridTable").jqGridRowValue("zlinterval");
//            var pirce=$("#gridTable").jqGridRowValue("pirce");
            if (checkedRow(keyValue)) {
                $.SetForm({
                    url: "/deleveryPrice/selectBean.action",
                    param: {tableName:"JC_DELIVERY_PRICE",id: id },
                    success: function (data) {
                         console.log(data);
                        $("#form1").SetWebControls(data);
                    }
                });
            }
        }

        function GetGrid() {
            var url="/deleveryPrice/getDeleveryPriceList.action?id="+keyValue;
            var selectedRowIndex = 0;
            var $gridTable = $('#gridTable');
            $gridTable.jqGrid({
                url: url,
                datatype: "json",
                height: $(window).height() - 170,
                autowidth: true,
                colModel: [
                    {label: '主键', name: 'id', hidden: true},
                    {label: '名称', name: 'name', width: 100, align: 'center'},
                    {label: '类型', name: 'zlinterval', width: 200, align: 'center',
                        formatter:function(cellvalue,options,rowObject){
                          if(cellvalue != 'undefined' && cellvalue !=undefined){
                              return top.clientdataItem.zlinterval['' + cellvalue + '']
                          }else{
                              return '';
                          }
                        }
                    },
                    {label: '单价', name: 'pirce', width: 100, align: 'center'},
                    {label: '备注', name: 'height', width: 80, align: 'center'},
                    {label: '创建人', name: 'create_Name', width: 120,align: 'center'},
                    {label: '创建时间', name: 'create_Time',type:"date", width: 150,align: 'center',
                        formatter:function(cellvalue, options, row){
                            if(cellvalue == null || cellvalue == undefined || cellvalue ==""){
                                return "";
                            }
                            return new Date(cellvalue).format("yyyy-MM-dd hh:mm:ss")
                        }
                    },
                    {label: '修改人', name: 'modify_Name', width: 120,align: 'center'},
                    {label: '修改时间', name: 'modify_Time',type:"date", width: 150,align: 'center',
                        formatter:function(cellvalue, options, row){
                            if(cellvalue == null || cellvalue == undefined || cellvalue ==""){
                                return "";
                            }
                            return new Date(cellvalue).format("yyyy-MM-dd hh:mm:ss")
                        }
                    },
                ],
                viewrecords: true,
                rowNum: 50,
                rowList: [30, 50, 100],
                pager: "#gridPager",
                rownumbers: true,
                shrinkToFit: false,
                gridview: true,
                multiselect: true,//复选框
                multiboxonly: true,
                onSelectRow: function () {
                    selectedRowIndex = $("#" + this.id).getGridParam('selrow');
                },
                gridComplete: function () {
                    $("#" + this.id).setSelection(selectedRowIndex, false);
                },
                ondblClickRow:function(a,b,c){
                    btn_edit(  $gridTable.getCell(a,"id"))
                },

            });
            //$gridTable.authorizeColModel()
            //初始化查询条件
            initJGGridselectView($gridTable);
        }
    </script>
    <div style="margin-left: 10px; margin-right: 10px;">
        <div class="tab-content" style="padding-top: 15px;">
            <table class="form">
                <input id="id" name="id" type="hidden" value="" />
                <tr>
                    <td class="formTitle">名称</td>
                    <td class="formValue">
                        <input  id="name"  type="text"  class="form-control"/>
                    </td>
                    <td class="formTitle">类型</td>
                    <td class="formValue">
                        <div id="zlinterval"  type="select" class="ui-select"/>
                    </td>
                    <th class="formTitle">单价<font face="宋体">*</font></th>
                    <td class="formValue">
                        <input id="pirce" autocomplete="off" name="pirce" class="form-control" isvalid="yes" checkexpession="NotNull" ></input>
                    </td>
                </tr>
                <tr>
                    <th class="formTitle">备注</th>
                    <td class="formValue">
                        <textarea id="description" type="text" style="width: 500px;height: 40px" class="form-control"></textarea>
                        <%--<input id="description" type="text" style="width: 500px;height: 50px" class="form-control" />--%>
                    </td>
                </tr>
            </table>
            <div id="ExpandInfo" class="tab-pane ">
                <div class="app_layout app_preview" style="border-top: 1px solid #ccc;" id="frmpreview"></div>
            </div>
            <a id="btn_add" class="btn btn-primary" onclick="AcceptClick()"><i class="fa fa-floppy-o"></i>&nbsp;保存</a>
            <a id="btn_edit" class="btn btn-primary" onclick="btn_edit()"><i class="fa fa-edit"></i>&nbsp;编辑</a>
            <a id="btn_reload" class="btn btn-primary" onclick="reload()"><i class="fa fa-edit"></i>&nbsp;刷新</a>
        </div>
    </div>
</form>
<div class="gridPanel">
    <table id="gridTable"></table>
    <%--<div id="gridPager"></div>--%>
</div>
</body>
</html>
